package Leo.configure;

import org.springframework.cache.CacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.cache.RedisCacheConfiguration;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.data.redis.cache.RedisCacheWriter;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import redis.clients.jedis.Jedis;

import java.time.Duration;

@Configuration
public class BeanFactory {

//    @Bean
//    public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) {
//        //springboot 2.x 写法
//        RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig()
//                .entryTtl(Duration.ofHours(1)); // 设置缓存有效期一小时
//        return RedisCacheManager
//                .builder(RedisCacheWriter.nonLockingRedisCacheWriter(redisConnectionFactory))
//                .cacheDefaults(redisCacheConfiguration).build();
//        //springboot 1.x写法可以看原文
////        ---------------------
////                作者：简简单单OnlineZuozuo
////        来源：CSDN
////        原文：https://blog.csdn.net/qq_15071263/article/details/82897330
////        版权声明：本文为博主原创文章，转载请附上博文链接！
//    }

//    @Bean
//    public Jedis getJedis(){
//        Jedis jedis = new Jedis("192.168.80.251",6379);
//        jedis.auth("southmax");
//        return jedis;
//    }
}
